package com.animator.learn;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.animation.BounceInterpolator;
import android.widget.TextView;

public class ObjectAnimatorTest {
	private TextView textView = null;
	
	public static void main(String[] args) {
		ObjectAnimatorTest oat = new ObjectAnimatorTest();
		oat.test1();
	}

	private void test1() {
		/**
		 * 第二个参数对应的第一参数类中一定要有setAlpha和getAlpha方法
		 */
		ObjectAnimator objAnim = ObjectAnimator.ofFloat(textView, "alpha", 1f, 0f, 1f);
		objAnim.setDuration(5000);
		objAnim.start();
	}
	
	
	private void test2() {
		ObjectAnimator objAnim = ObjectAnimator.ofFloat(textView, "rotation", 0f, 360f);
		objAnim.setDuration(500);
		objAnim.start();
	}
	
	private void testAnimatorSet() {
		ObjectAnimator moveIn = ObjectAnimator.ofFloat(textView, "translationX", -500f, 0f);
		ObjectAnimator rotate = ObjectAnimator.ofFloat(textView, "rotation", 0f, 360f);
		ObjectAnimator fadeInOut = ObjectAnimator.ofFloat(textView, "alphpa", 1f, 0f, 1f);
		
		AnimatorSet animSet = new AnimatorSet();
		animSet.play(moveIn).with(rotate).after(rotate);
		animSet.setDuration(5000);
		
		animSet.addListener(new AnimatorListenerAdapter() {
			@Override
			public void onAnimationStart(Animator animation) {
				super.onAnimationStart(animation);
			}
		});
		
		animSet.start();
	}
	
	
	private void testXMLAnim() {
		/**
		 * Animator animator = AnimatorInflater.loadAnimator(context, R.animator.anim_file);  
		 * animator.setTarget(view);  
		 * animator.start();  
		 */
	}
	
	public void testViewPropertyAnimator() {
		textView.animate().x(500).y(500).setDuration(5000).setInterpolator(new BounceInterpolator()).start();
		
	}
}
